from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
from PyQt6.QtGui import *

'''子窗口'''
#获取文件所在路径（FilePath会获取到本文件）
root = QFileInfo(__file__).absolutePath()
#平滑处理
class FilterChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("图像平滑处理")
        print(root)
        #要用绝对路径才能奏效
        self.setWindowIcon(QIcon(root + "\\UI_image\\filter_icon.png"))
        self.fliter_table = QTableWidget()
        filter_vbox = QVBoxLayout()

        self.fliter_kind_combox = QComboBox()
        self.fliter_kind_combox.addItem("均值滤波")        
        self.fliter_kind_combox.addItem("高斯滤波")   
        self.fliter_kind_combox.addItem("中值滤波")

        self.fliter_ksize_spinbox = QSpinBox()
        self.fliter_ksize_spinbox.setValue(3)
        self.fliter_ksize_spinbox.setMinimum(1)
        self.fliter_ksize_spinbox.setSingleStep(2)


        self.fliter_table.setColumnCount(2)
        self.fliter_table.setRowCount(2)
        self.fliter_table.setItem(0,0,QTableWidgetItem("类型"))
        self.fliter_table.setCellWidget(0,1,self.fliter_kind_combox)
        self.fliter_table.setItem(1,0,QTableWidgetItem("核大小"))
        self.fliter_table.setCellWidget(1,1,self.fliter_ksize_spinbox)
        filter_vbox.addWidget(self.fliter_table)
        self.setLayout(filter_vbox)


#形态学
class MorphChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("形态学")
        self.setWindowIcon(QIcon(root + "\\UI_image\\morph_icon.png"))
        self.morph_table = QTableWidget()
        morph_vbox = QVBoxLayout()
        self.morph_kind_combox = QComboBox()
        self.morph_kind_combox.addItem("腐蚀操作")        
        self.morph_kind_combox.addItem("膨胀操作")   
        self.morph_kind_combox.addItem("开操作")
        self.morph_kind_combox.addItem("闭操作")
        self.morph_kind_combox.addItem("梯度操作")
        self.morph_kind_combox.addItem("顶帽操作")
        self.morph_kind_combox.addItem("黑帽操作")

        self.morph_ksize_spinbox = QSpinBox()
        self.morph_ksize_spinbox.setValue(3)
        self.morph_ksize_spinbox.setMinimum(1)
        self.morph_ksize_spinbox.setSingleStep(2)

        self.morph_kshape_combox = QComboBox()
        self.morph_kshape_combox.addItem("方形")
        self.morph_kshape_combox.addItem("十字形")
        self.morph_kshape_combox.addItem("椭圆形")

        self.morph_table.setColumnCount(2)
        self.morph_table.setRowCount(3)
        self.morph_table.setItem(0,0,QTableWidgetItem("类型"))
        self.morph_table.setCellWidget(0,1,self.morph_kind_combox)
        self.morph_table.setItem(1,0,QTableWidgetItem("核大小"))
        self.morph_table.setCellWidget(1,1,self.morph_ksize_spinbox)
        self.morph_table.setItem(2,0,QTableWidgetItem("核形状"))
        self.morph_table.setCellWidget(2,1,self.morph_kshape_combox)
        morph_vbox.addWidget(self.morph_table)
        self.setLayout(morph_vbox)

#图像梯度
class GradChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("图像梯度")
        self.setWindowIcon(QIcon(root + "\\UI_image\\grad_icon.png"))
        self.grad_table = QTableWidget()
        grad_vbox = QVBoxLayout()
        self.grad_kind_combox = QComboBox()
        self.grad_kind_combox.addItem("Sobel算子")    
        self.grad_kind_combox.addItem("Scharr算子")
        self.grad_kind_combox.addItem("Laplacian算子")

        self.grad_dx_spinbox = QSpinBox()
        self.grad_dx_spinbox.setValue(1)
        self.grad_dx_spinbox.setMinimum(0)
        self.grad_dx_spinbox.setMaximum(1)
        self.grad_dx_spinbox.setSingleStep(1)

        self.grad_dy_spinbox = QSpinBox()
        self.grad_dy_spinbox.setMinimum(0)
        self.grad_dy_spinbox.setMaximum(1)
        self.grad_dy_spinbox.setSingleStep(1)

        self.grad_table.setColumnCount(2)
        self.grad_table.setRowCount(3)
        self.grad_table.setItem(0,0,QTableWidgetItem("类型"))
        self.grad_table.setCellWidget(0,1,self.grad_kind_combox)
        self.grad_table.setItem(1,0,QTableWidgetItem("x方向"))
        self.grad_table.setCellWidget(1,1,self.grad_dx_spinbox)
        self.grad_table.setItem(2,0,QTableWidgetItem("y方向"))
        self.grad_table.setCellWidget(2,1,self.grad_dy_spinbox)
        grad_vbox.addWidget(self.grad_table)
        self.setLayout(grad_vbox)

#阈值处理
class ThresholdChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("阈值处理")
        self.setWindowIcon(QIcon(root + "\\UI_image\\threshold_icon.png"))
        self.threshold_table = QTableWidget()
        threshold_vbox = QVBoxLayout()

        self.threshold_kind_combox = QComboBox()
        self.threshold_kind_combox.addItem("二值化阈值处理")    
        self.threshold_kind_combox.addItem("反二值化阈值处理")
        self.threshold_kind_combox.addItem("截断阈值化处理")
        self.threshold_kind_combox.addItem("超阈值零处理")
        self.threshold_kind_combox.addItem("低阈值零处理")
        
        self.threshold_thresh_spinbox = QSpinBox()
        self.threshold_thresh_spinbox.setMinimum(0)
        self.threshold_thresh_spinbox.setMaximum(255)
        #默认范围为0~99
        self.threshold_thresh_spinbox.setValue(127)
        self.threshold_thresh_spinbox.setSingleStep(1)

        self.threshold_maxval_spinbox = QSpinBox()
        self.threshold_maxval_spinbox.setMinimum(0)
        self.threshold_maxval_spinbox.setMaximum(255)
        #默认范围0~99
        self.threshold_maxval_spinbox.setValue(255)
        self.threshold_maxval_spinbox.setSingleStep(1)

        self.threshold_table.setColumnCount(2)
        self.threshold_table.setRowCount(3)
        self.threshold_table.setItem(0,0,QTableWidgetItem("类型"))
        self.threshold_table.setCellWidget(0,1,self.threshold_kind_combox)
        self.threshold_table.setItem(1,0,QTableWidgetItem("阈值"))
        self.threshold_table.setCellWidget(1,1,self.threshold_thresh_spinbox)
        self.threshold_table.setItem(2,0,QTableWidgetItem("最大值"))
        self.threshold_table.setCellWidget(2,1,self.threshold_maxval_spinbox)

        threshold_vbox.addWidget(self.threshold_table)
        self.setLayout(threshold_vbox)

#边缘检测
class EdgeChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("边缘检测")
        self.setWindowIcon(QIcon(root + "\\UI_image\\edge_icon.png"))
        self.edge_table = QTableWidget()
        edge_vbox = QVBoxLayout()

        self.edge_threshold1_spinbox = QSpinBox()
        self.edge_threshold1_spinbox.setValue(20)
        self.edge_threshold1_spinbox.setMinimum(0)
        self.edge_threshold1_spinbox.setMaximum(255)
        self.edge_threshold1_spinbox.setSingleStep(1)

        self.edge_threshold2_spinbox = QSpinBox()
        self.edge_threshold2_spinbox.setMinimum(0)
        self.edge_threshold2_spinbox.setMaximum(255)
        #默认范围0~99
        self.edge_threshold2_spinbox.setValue(100)
        self.edge_threshold2_spinbox.setSingleStep(1)

        self.edge_table.setRowCount(2)
        self.edge_table.setColumnCount(2)

        self.edge_table.setItem(0,0,QTableWidgetItem("阈值1"))
        self.edge_table.setCellWidget(0,1,self.edge_threshold1_spinbox)
        self.edge_table.setItem(1,0,QTableWidgetItem("阈值2"))
        self.edge_table.setCellWidget(1,1,self.edge_threshold2_spinbox)

        edge_vbox.addWidget(self.edge_table)
        self.setLayout(edge_vbox)

#轮廓检测
class ContourChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("轮廓检测")
        self.setWindowIcon(QIcon(root + "\\UI_image\\contour_icon.png"))
        self.contour_table = QTableWidget()
        contour_vbox = QVBoxLayout()

        self.contour_mode_combobox = QComboBox()
        self.contour_mode_combobox.addItem("外轮廓")
        self.contour_mode_combobox.addItem("轮廓列表")
        self.contour_mode_combobox.addItem("外轮廓与内孔")
        self.contour_mode_combobox.addItem("轮廓等级树")
        self.contour_mode_combobox.setCurrentIndex(0)

        self.contour_method_combobox = QComboBox()
        self.contour_method_combobox.addItem("简易近似")
        self.contour_method_combobox.setCurrentIndex(0)

        self.contour_table.setColumnCount(2)
        self.contour_table.setRowCount(2)

        self.contour_table.setItem(0,0,QTableWidgetItem("轮廓检索模式"))
        self.contour_table.setCellWidget(0,1,self.contour_mode_combobox)
        self.contour_table.setItem(1,0,QTableWidgetItem("轮廓近似方法"))
        self.contour_table.setCellWidget(1,1,self.contour_method_combobox)

        contour_vbox.addWidget(self.contour_table)
        self.setLayout(contour_vbox)

#均衡化
class EqualizeChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("均衡化")
        self.setWindowIcon(QIcon(root + "\\UI_image\\equalize_icon.png"))
        self.equalize_table = QTableWidget()
        equalize_vbox = QVBoxLayout()

        self.equalize_red_checkBox = QCheckBox()
        self.equalize_red_checkBox.setChecked(True)

        self.equalize_blue_checkBox = QCheckBox()
        self.equalize_blue_checkBox.setChecked(True)

        self.equalize_green_checkBox = QCheckBox()
        self.equalize_green_checkBox.setChecked(True)

        self.equalize_table.setColumnCount(2)
        self.equalize_table.setRowCount(3)

        self.equalize_table.setItem(0,0,QTableWidgetItem("R通道"))
        self.equalize_table.setCellWidget(0,1,self.equalize_red_checkBox)
        self.equalize_table.setItem(1,0,QTableWidgetItem("G通道"))
        self.equalize_table.setCellWidget(1,1,self.equalize_green_checkBox)
        self.equalize_table.setItem(2,0,QTableWidgetItem("B通道"))
        self.equalize_table.setCellWidget(2,1,self.equalize_blue_checkBox)

        equalize_vbox.addWidget(self.equalize_table)
        self.setLayout(equalize_vbox)

#直线检测
class HoughLineChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("直线检测")
        self.setWindowIcon(QIcon(root + "\\UI_image\\houghline_icon.png"))
        self.houghline_table = QTableWidget()
        houghline_vbox = QVBoxLayout()

        self.houghline_thresh_spinbox = QSpinBox()
        self.houghline_thresh_spinbox.setMinimum(0)
        self.houghline_thresh_spinbox.setMaximum(270)
        self.houghline_thresh_spinbox.setSingleStep(1)
        self.houghline_thresh_spinbox.setValue(100)

        self.houghline_min_length_spinbox = QSpinBox()
        self.houghline_min_length_spinbox.setMinimum(0)
        self.houghline_min_length_spinbox.setSingleStep(1)
        self.houghline_min_length_spinbox.setValue(20)

        self.houghline_max_gap_spinbox = QSpinBox()
        self.houghline_max_gap_spinbox.setMinimum(0)
        self.houghline_max_gap_spinbox.setSingleStep(1)
        self.houghline_max_gap_spinbox.setValue(5)

        self.houghline_table.setColumnCount(2)
        self.houghline_table.setRowCount(3)

        self.houghline_table.setItem(0,0,QTableWidgetItem("阈值"))
        self.houghline_table.setCellWidget(0,1,self.houghline_thresh_spinbox)
        self.houghline_table.setItem(1,0,QTableWidgetItem("最小长度"))
        self.houghline_table.setCellWidget(1,1,self.houghline_min_length_spinbox)
        self.houghline_table.setItem(2,0,QTableWidgetItem("最大间距"))
        self.houghline_table.setCellWidget(2,1,self.houghline_max_gap_spinbox)

        houghline_vbox.addWidget(self.houghline_table)
        self.setLayout(houghline_vbox)

#亮度调节
class LightChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("亮度调节")
        self.setWindowIcon(QIcon(root + "\\UI_image\\light_icon.png"))
        self.light_table = QTableWidget()
        light_vbox = QVBoxLayout()

        self.light_alpha_spinbox = QDoubleSpinBox()
        self.light_alpha_spinbox.setMinimum(0)
        self.light_alpha_spinbox.setMaximum(3)
        self.light_alpha_spinbox.setSingleStep(0.1)
        self.light_alpha_spinbox.setValue(0.2)

        self.light_beta_spinbox = QSpinBox()
        self.light_beta_spinbox.setMinimum(0)
        self.light_beta_spinbox.setSingleStep(1)

        self.light_table.setColumnCount(2)
        self.light_table.setRowCount(2)

        self.light_table.setItem(0, 0, QTableWidgetItem('alpha'))
        self.light_table.setCellWidget(0, 1, self.light_alpha_spinbox)
        self.light_table.setItem(1, 0, QTableWidgetItem('beta'))
        self.light_table.setCellWidget(1, 1, self.light_beta_spinbox)

        light_vbox.addWidget(self.light_table)
        self.setLayout(light_vbox)

#伽马
class GammaChild(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("伽马校正")
        self.setWindowIcon(QIcon(root + "\\UI_image\\gamma_icon.png"))
        gamma_vbox = QVBoxLayout()
        self.gamma_table = QTableWidget()

        self.gamma_spinbox = QDoubleSpinBox()
        self.gamma_spinbox.setMinimum(0)
        self.gamma_spinbox.setSingleStep(0.1)
        self.gamma_spinbox.setValue(0.1)

        self.gamma_table.setColumnCount(2)
        self.gamma_table.setRowCount(1)

        self.gamma_table.setItem(0, 0, QTableWidgetItem('gamma'))
        self.gamma_table.setCellWidget(0, 1, self.gamma_spinbox)

        gamma_vbox.addWidget(self.gamma_table)
        self.setLayout(gamma_vbox)